package cn.structure.edp;

import cn.structure.ClassEntity;
import cn.structure.MethodEntity;
import cn.structure.VariableEntity;

import java.util.Objects;

public class RedirectedRecursion extends EdpEntity {
    private ClassEntity recursor;
    private VariableEntity redirectTarget;
    private MethodEntity operation;

    public RedirectedRecursion(ClassEntity recursor, VariableEntity redirectTarget, MethodEntity operation) {
        super();
        this.recursor = recursor;
        this.redirectTarget = redirectTarget;
        this.operation = operation;
    }

    public enum Role {
        recursor, redirectTarget, operation
    }

    public ClassEntity getRecursor() {
        return recursor;
    }

    public void setRecursor(ClassEntity recursor) {
        this.recursor = recursor;
    }

    public VariableEntity getRedirectTarget() {
        return redirectTarget;
    }

    public void setRedirectTarget(VariableEntity redirectTarget) {
        this.redirectTarget = redirectTarget;
    }

    public MethodEntity getOperation() {
        return operation;
    }

    public void setOperation(MethodEntity operation) {
        this.operation = operation;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("RedirectedRecursion{\n\t");
        sb.append(super.toString());
        sb.append("\n\t\"recursor\":")
                .append(recursor);
        sb.append(",\n\t\"redirectTarget\":")
                .append(redirectTarget);
        sb.append(",\n\t\"operation\":")
                .append(operation);
        sb.append("\n}");
        return sb.toString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;
        RedirectedRecursion that = (RedirectedRecursion) o;
        return Objects.equals(recursor, that.recursor) &&
                Objects.equals(redirectTarget, that.redirectTarget) &&
                Objects.equals(operation, that.operation);
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), recursor, redirectTarget, operation);
    }
}
